<?php
include_once("conn/conn.php");
include_once("function.php");
if(isset($_SESSION['usernc'])){
	$sql=mysql_query("select id from tb_user where usernc='".$_SESSION['usernc']."'");
	$info=mysql_fetch_array($sql);
	$userid=$info['id'];
}
if(isset($_SESSION['useword'])){
	$sql=mysql_query("select id from tb_adm where useword='".$_SESSION['useword']."'");
	$info=mysql_fetch_array($sql);
	$userid=$info['id'];
}
if(isset($_POST['content'])){
		if(is_file("filterwords.txt")){
			$filter_word = file("filterwords.txt");
			$content=$_POST['content'];
			$title=$_POST['title'];
			for($i=0;$i<count($filter_word);$i++){
				if(preg_match("/".trim($filter_word[$i])."/",$content)){
					echo "<script>alert('留言信息中包含敏感词！');history.back(-1);</script>";
					exit;
				}
			}
		}
		$createtime=date("Y-m-d,H:m:s");
		if(mysql_query("insert into tb_leaveword(userid,createtime,title,content)values('$userid','$createtime','$title','$content')")){	//插入留言信息至数据库中
			echo "<script>alert('留言发表成功！');window.location.href='index.php?id=".urlencode('查看留言')."';<script>";
		}else{
			echo "<script>alert('留言发表失败！');history.back();<script>";
		}
}
?>